package br.com.sgpv2.controler.relatorio;

import java.util.Locale;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import br.com.sgpv2.controler.SGPController;
import br.com.sgpv2.datasource.folha.RelatorioCriticaDataSource;
import br.com.sgpv2.service.folha.FolhaService;

@Controller
public class RelatorioCriticaController extends SGPController {
	
	@Autowired
	private FolhaService folhaService;
	
	@Autowired
	private ServletContext servletContext;

	@RequestMapping(value = "/relatorio_critica", method = RequestMethod.GET)
	public String relatorioCritica(Locale locale, Model model) throws Exception {
		model.addAttribute("folhas", folhaService.consultarFolhas());
		return "relatorio.critica";
	}
	
	@RequestMapping(value = "/relatorio_critica/gerar", method = RequestMethod.POST)
	public String gerarCritica(@RequestParam(required = true) Integer idFolha, Locale locale, Model model) throws Exception {
		
		new RelatorioCriticaDataSource(folhaService.buscar(idFolha), model);
		model.addAttribute("pathJasper", servletContext.getRealPath("/resources/jasper/"));
		return "relatorioCriticaReport";
	}
	
}
